<template>
<div class="homedata">
    <div class="content_box">
      <!-- 左侧区域 -->
      <div class="left_box"> 
        <div class="part">
            <div class="top">
              <el-button type="primary" size="mini"  @click="handAdd(1)">添加</el-button>
              <el-button type="warning" size="mini" @click="handModify">修改</el-button>
              <el-button type="danger" size="mini"   @click="handDelete">删除</el-button>
            </div>
            <div class="table">
      <div class="table_box">
        <el-table
        :data="data"
        style="width: 100%;margin-bottom: 20px;"
        row-key="id"
        size="mini"
        border
        default-expand-all
        @selection-change="handleSelectionChange"
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
        <el-table-column
          type="selection"
          width="40">
        </el-table-column>
        <el-table-column
          prop="label"
          label="部门名称"
          width="">
          <template slot-scope="scope">
            <!-- <span  class="el-icon-eleme iconbox"></span>
            <span class="icon-pageIcon iconbox"></span> -->
            {{scope.row.label}}
             <span class="blue" v-show="scope.row.type != 2 "  @click="handAdd(2)" style="float: right;">添加</span>
             <span class="blue" v-show="scope.row.type != 1 "  @click="handfill" style="float: right;">新建</span>
          </template>
        </el-table-column>
      </el-table>
      </div>
    </div>


          </div>
      </div>
      <!-- 右侧 -->
      <div class="right_box">
        <div class="right_box_list">
          <el-table :data="tableData" stripe style="width: 100%">
            <el-table-column type="index" label="序号"  width="50">
            </el-table-column>
            <el-table-column prop="channelO" align="center" label="通道1">
            </el-table-column>
            <el-table-column prop="channelT" align="center" label="通道2">
            </el-table-column>
            <el-table-column prop="channelS" align="center" label="通道3">
            </el-table-column>
            <el-table-column prop="channelF" align="center" label="通道4">
            </el-table-column>
            <el-table-column prop="num" align="center" label="数量">
            </el-table-column>
            <el-table-column prop="explain" align="center" label="说明">
            </el-table-column>
            <el-table-column prop="stateO" align="center" label="通道1状态">
            </el-table-column>
            <el-table-column prop="stateT" align="center" label="通道2状态">
            </el-table-column>
            <el-table-column prop="stateS" align="center" label="通道3状态">
            </el-table-column>
            <el-table-column prop="stateF" align="center" label="通道4状态">
            </el-table-column>
            <el-table-column prop="sensorO" align="center" label="传感器12距离">
            </el-table-column>
            <el-table-column prop="sensorT" align="center" label="传感器12距离">
            </el-table-column>
            <el-table-column prop="sensorS" align="center" label="传感器12距离">
            </el-table-column>
            <el-table-column prop="meterName" label="采集状态" width="120" align="center">
              <template slot-scope="scope">
                <el-switch v-model="scope.row.state" active-color="#13ce66" :active-value="1" :inactive-value="0"
                  active-text="采集" inactive-text="不采集" inactive-color="#ff4949" :width="50"
                  @change="handlePubChange(scope.row)">
                </el-switch>
              </template>
            </el-table-column>
            <el-table-column align="center" label="操作" width="190">
              <el-button size="mini">修改</el-button>
              <el-button size="mini" type="danger">删除</el-button>
              <el-button size="mini" type="primary">查看数据</el-button>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
     <!-- 填写通道名称和说明弹出框 -->
    <el-dialog :close-on-click-modal="false" title="填写通道名称和说明" :visible.sync="fillDialog" width="650px" class="tian">
      <el-form :inline="true" :model="data_obj" class="demo-form-inline float" size="mini" label-width="70px" ref="dictoryAddForm">
        <el-form-item label="通道1" >
          <el-input v-model="data_obj.Channel_1" placeholder="请输入内容" class="Channel_1"></el-input>
        </el-form-item>
        <el-form-item label="通道2" >
          <el-input v-model="data_obj.Channel_2" placeholder="请输入内容" class="Channel_1" :disabled="showNum1[0]"></el-input>
        </el-form-item>
        <el-form-item label="通道3" >
          <el-input v-model="data_obj.Channel_3" placeholder="请输入内容" class="Channel_1" :disabled="showNum1[1]"></el-input>
        </el-form-item>
        <el-form-item label="通道4" >
          <el-input v-model="data_obj.Channel_4" placeholder="请输入内容" class="Channel_1" :disabled="showNum1[2]"></el-input>
        </el-form-item>
        <div  class="public">
          <div class="isuse">
            <el-radio v-model="data_obj.sensor_1" label="1">停止使用</el-radio>
            <el-radio v-model="data_obj.sensor_1" label="2">投入使用</el-radio>
            <el-radio v-model="data_obj.sensor_1" label="3">环境采集</el-radio>
          </div>
          <div class="isuse">
            <el-radio v-model="data_obj.sensor_2" label="1" :disabled="showNum2[0]">停止使用</el-radio>
            <el-radio v-model="data_obj.sensor_2" label="2" :disabled="showNum2[0]">投入使用</el-radio>
            <el-radio v-model="data_obj.sensor_2" label="3" :disabled="showNum2[0]">环境采集</el-radio>
          </div>
          <div class="isuse">
            <el-radio v-model="data_obj.sensor_3" label="1" :disabled="showNum2[1]">停止使用</el-radio>
            <el-radio v-model="data_obj.sensor_3" label="2" :disabled="showNum2[1]">投入使用</el-radio>
            <el-radio v-model="data_obj.sensor_3" label="3" :disabled="showNum2[1]">环境采集</el-radio>
          </div>
          <div class="isuse">
            <el-radio v-model="data_obj.sensor_4" label="1" :disabled="showNum2[2]">停止使用</el-radio>
            <el-radio v-model="data_obj.sensor_4" label="2" :disabled="showNum2[2]">投入使用</el-radio>
            <el-radio v-model="data_obj.sensor_4" label="3" :disabled="showNum2[2]">环境采集</el-radio>
          </div>
        </div>
        <div style="padding: 20px;">
          <el-steps :active="data_obj.sensorProgress" finish-status="success">
            <el-step title="sensor.1"></el-step>
            <el-step title="sensor.2"></el-step>
            <el-step title="sensor.3"></el-step>
            <el-step title="sensor.4"></el-step>
          </el-steps>
        </div>
        <div  class="public">
          <el-form-item label="12间距" >
            <el-input v-model="data_obj.spacing1" placeholder="请输入内容" class="spacing"></el-input>m
          </el-form-item>
          <el-form-item label="23间距" >
            <el-input v-model="data_obj.spacing1" placeholder="请输入内容" class="spacing"></el-input>m
          </el-form-item>
          <el-form-item label="34间距" >
            <el-input v-model="data_obj.spacing1" placeholder="请输入内容" class="spacing"></el-input>m
          </el-form-item>
        </div>
        <el-form-item label="说明" >
          <el-input v-model="data_obj.explain" placeholder="请输入内容" class="Channel_1"></el-input>
        </el-form-item>
        </el-form>
      <div slot="footer" class="dialog-footer" style="display:block">
        <el-button @click="fillDialog = false" size="mini">取 消</el-button>
        <el-button type="primary" size="mini">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 添加弹出框 -->
    <el-dialog :close-on-click-modal="false" title="新建" :visible.sync="addDialog" width="650px" class="tian">
      <div > 
        <span class="public" v-if="addTest== 1 ">请输入文件夹名：</span>
        <span class="public" v-if="addTest== 2 ">请输入文件名：</span>
          <el-input v-model="folderName" placeholder="请输入" clearable></el-input>
      </div>
      <div slot="footer" class="dialog-footer" style="display:block">
        <el-button @click="addDialog = false" size="mini">取 消</el-button>
        <el-button type="primary" size="mini">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 修改弹出框 -->
    <el-dialog :close-on-click-modal="false" title="修改" :visible.sync="modifyDialog" width="650px" class="tian">
      <div > 
        <span class="public" >文件夹名：</span>
          <el-input v-model="modifyfoldName" placeholder="请输入" clearable></el-input>
      </div>
        
      <div slot="footer" class="dialog-footer" style="display:block">
        <el-button @click="modifyDialog = false" size="mini">取 消</el-button>
        <el-button type="primary" size="mini">确 定</el-button>
      </div>
    </el-dialog>
     <!-- 采集弹出框 -->
    <el-dialog :close-on-click-modal="false" title="采集参数确认" :visible.sync="collectionDialog" width="650px" class="tian">
        <el-form :inline="true" :model="collection_data" class="demo-form-inline float" size="mini" label-width="110px" ref="dictoryAddForm">
          <div class="public">
            <el-form-item label="相位通道序号" >
              <el-input v-model="collection_data.comId" placeholder="请输入内容" class="Channel_2"></el-input>
            </el-form-item>
            <div>
            <el-button type="primary" size="mini" >刷新</el-button>
            </div>
          </div>
          <div>
            <el-form-item label="时基设置" >
              <el-input v-model="collection_data.timeBase" placeholder="请输入内容" class="Channel_1"></el-input>
            </el-form-item>
            <el-form-item label="阀值设置" >
              <el-input v-model="collection_data.threshold" placeholder="请输入内容" class="Channel_1"></el-input>
            </el-form-item>
          </div>
           <el-form-item label="示波器接口地址">
            <el-input type="textarea" v-model="collection_data.address" class="Channel_1"></el-input>
          </el-form-item>
          <div class="public">
            <el-form-item label="分段采集数量" >
              <el-input v-model="collection_data.quantity" placeholder="请输入内容" class="spacing"></el-input>
            </el-form-item>
            <el-form-item label="" >
              <el-input v-model="collection_data.subsection" placeholder="请输入内容" ></el-input>
            </el-form-item>
            <div>
                <el-button type="primary" size="mini">开始</el-button>
            </div>
          </div>
        
        </el-form>
      <div slot="footer" class="dialog-footer" style="display:block">
        <el-button @click="collectionDialog = false" size="mini">取 消</el-button>
        <el-button type="primary" size="mini">确 定</el-button>
      </div>
    </el-dialog>
</div>
</template>
<script>
let id = 1000;
  export default {
    data() {
      return {
        multipleSelection: [],  //选中数据组成的数组
        fillDialog:false,//填写通道名称和说明
        addDialog:false,//新建
        modifyDialog:false,//修改
        collectionDialog:false,//采集参数确认
        modifyfoldName:'',
        data_obj:{
          Channel_1:'',
          Channel_2:'',
          Channel_3:'',
          Channel_4:'',
          sensor_1:'1',
          sensor_2:'1',
          sensor_3:'1',
          sensor_4:'1',
          explain:'',
          sensorProgress:0,
          spacing1:'',
          spacing2:'',
          spacing3:'',
          },
        collection_data:{
            comId:'',
            timeBase:'',
            threshold:'',
            address:'',
            subsection:'',
            quantity:'',

        },
        data : [{
        id: 1,
        label: '一级 1',
        type:1,
        children: [{
          id: 4,
          label: '二级 1-1',
          type:1,
          children: [{
            id: 9,
            label: '三级 1-1-1',
            type:2,
          }, {
            id: 10,
            label: '三级 1-1-2',
            type:2,
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        type:1,
        children: [{
          id: 5,
          label: '二级 2-1',
          type:2,
        }, {
          id: 6,
          label: '二级 2-2',
          type:2,
        }]
      }, {
        id: 3,
        label: '一级 3',
        type:1,
        children: [{
          id: 7,
          label: '二级 3-1',
          type:2,
        }, {
          id: 8,
          label: '二级 3-2',
          type:2,
        }]
      }],
        addTest:'',
        folderName:'',
        tableData: [
           {id:"1",channelO:'通道1',channelT:'通道2',channelS:'通道1',channelF:'通道1',explain:"说明说明",num:"1231",stateO:"投入",
           stateT:"投入",stateS:"投入",stateF:"停止",sensorO:"1.0",sensorT:"2.0",sensorS:"1.0",state:0},
           {id:"2",channelO:'通道1',channelT:'通道2',channelS:'通道1',channelF:'通道1',explain:"说明说明",num:"1231",stateO:"投入",
           stateT:"投入",stateS:"投入",stateF:"停止",sensorO:"1.0",sensorT:"2.0",sensorS:"1.0",state:0},
           {id:"3",channelO:'通道1',channelT:'通道2',channelS:'通道1',channelF:'通道1',explain:"说明说明",num:"1231",stateO:"投入",
           stateT:"投入",stateS:"投入",stateF:"停止",sensorO:"1.0",sensorT:"2.0",sensorS:"1.0",state:0}
         ],
         showNum1:[true,true,true],
         showNum2:[true,true,true],
         id:""
      };
    },
    methods: {
      handlePubChange(data){
        if(data.id === this.id){
          this.id = ""
          this.tableData.forEach(item=>{
              item.state = 0;
          })
          return
        }
        this.collectionDialog=true;
        this.tableData.forEach(item=>{
          if(item.id === data.id){
            item.state = 1;
          }else{
            item.state = 0;
          }
        })
        this.id = data.id;
      },
      handfill(){
        this.fillDialog = true;
      },
      handleSelectionChange(val) {
        console.log(val);
        this.multipleSelection = val;
      }, 
      handDelete(){
        if(this.multipleSelection.length > 1 || this.multipleSelection.length == 0) {
          this.$confirm("请选择一条数据操作", '提示', {
            type: 'warning',
            customClass: "errormessage",
            showCancelButton: false,
            center: "true"
          }).then(() => {
          }).catch(() => {
          });
          return;
        }
        this.$confirm("确定删除当前数据吗？", '提示', {
          type: 'warning',
          customClass: "errormessage",
          showCancelButton: true,
          center: "true"
        }).then(() => {
          console.log('删除');
        }).catch(() => {
        });
      },
      handModify(){//修改
        if(this.multipleSelection.length > 1 || this.multipleSelection.length == 0) {
        this.$confirm("请选择一条数据操作", '提示', {
          type: 'warning',
          customClass: "errormessage",
          showCancelButton: false,
          center: "true"
        }).then(() => {
        }).catch(() => {
        });
        return;
      }
        this.modifyDialog = true;
        console.log(this.multipleSelection);
        this.modifyfoldName = this.multipleSelection[0].label;
      },
      handAdd(data){ //添加
        if(data==1){
          if(this.multipleSelection.length > 1 ) {
            this.$confirm("请选择一条数据操作", '提示', {
              type: 'warning',
              customClass: "errormessage",
              showCancelButton: false,
              center: "true"
            }).then(() => {
            }).catch(() => {
            });
            return;
          }
          this.addTest="1";
          if(this.multipleSelection.length == 0){
          }
        }else{
          this.addTest="2";
        }
        this.addDialog=true;
      },
    },
    watch: {
      'data_obj':{
        handler(){
          if(this.data_obj.Channel_1){
            this.showNum1[0] = false;
          }
          if(this.data_obj.Channel_2){
            this.showNum1[1] = false;
            this.showNum2[0] = false;
          }
          if(this.data_obj.Channel_3){
            this.showNum1[2] = false;
            this.showNum2[1] = false;
          }
          if(this.data_obj.Channel_4){
            this.showNum2[2] = false;
          }
          if(!this.data_obj.Channel_1){
            this.showNum1[0] = true;
            this.showNum1[1] = true;
            this.showNum1[2] = true;
            this.showNum2[0] = true;
            this.showNum2[1] = true;
            this.showNum2[2] = true;
            this.data_obj.Channel_2 = "";
            this.data_obj.Channel_3 = "";
            this.data_obj.Channel_4 = "";
            this.data_obj.sensor_2 = "1";
            this.data_obj.sensor_3 = "1";
            this.data_obj.sensor_4 = "1";
          }
          if(!this.data_obj.Channel_2){
            this.showNum1[1] = true;
            this.showNum1[2] = true;
            this.showNum2[0] = true;
            this.showNum2[1] = true;
            this.showNum2[2] = true;
            this.data_obj.Channel_3 = "";
            this.data_obj.Channel_4 = "";
            this.data_obj.sensor_3 = "1";
            this.data_obj.sensor_4 = "1";
          }
          if(!this.data_obj.Channel_3){
            this.showNum1[2] = true;
            this.showNum2[1] = true;
            this.showNum2[2] = true;
            this.data_obj.Channel_4 = "";
            this.data_obj.sensor_4 = "1";
          }
          if(!this.data_obj.Channel_4){
            this.showNum2[2] = true;
          }
        },
        deep:true
      }
    },
  };
</script>
<style scoped>
  .homedata {
    width: 100%;
    height: 882px;
    background-color: #fff;
    padding: 3px 8px;
    /* background-color: #30335f */
  }
  /* 弹框样式 */
  .homedata /deep/ .el-dialog__header {
  background: #2858a0  !important;
 }
 .homedata /deep/ .el-dialog__title{
  color: rgb(221, 219, 219) !important;
 }
  .homedata /deep/ .el-dialog__body {
    background: #eff3f7  !important;
  }
   .content_box {
    display: flex;
    width:100%;
    height: 100%;
  }
  /* 左侧区域 */
  .left_box {
    width: 17%;
    /* min-width: 200px; */
    height: 100%;
    background: #fff;
    border:1px solid #6699ffa9 ;
    overflow: auto;
    z-index: 10;
  }
  /* 右侧区域 */
  .right_box {
    height: 100%;
    width: 83%;
    background: #fff;
    padding-left: 8px;
  }
  .right_box_list{
    height: 100%;
    border:1px solid #6699ffa9 ;
  }
  .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 8px;
  }
  .filter-tree{
    overflow: hidden;
  }
  .homedata /deep/ .el-form-item--mini.el-form-item, .el-form-item--small.el-form-item{
    width: 100%;
  }
  /* .homedata /deep/ .el-input--mini .el-input__inner{
    width: 470px;
  } */
  .top{
    padding: 8px;
  }
  .isuse{
    border: 1px solid rgb(110, 110, 110);
    margin-right: 20px;
    padding: 5px;
    border-radius: 10px;
  }
  .Channel_1{
    width: 470px !important;
  }
  .Channel_2{
    width: 410px !important;
  }
  .spacing{
    width: 100px !important;
  }
  .public{
    display: flex;  
    margin-bottom: 15px;
  }
  .blue{
    color: rgb(22, 89, 212);
  }
   /* 开关按钮显示 */
  .homedata /deep/ .el-switch__label {
    position: absolute;
    display: none;
    color: #fff;
  }
  /*打开时文字位置设置*/
  .homedata /deep/ .el-switch__label--right {
    z-index: 1;
    right: 30px;
    top: 0;
  }
  /*关闭时文字位置设置*/
  .homedata /deep/ .el-switch__label--left {
    z-index: 1;
    left: 24px;
    top: 0;
  }
  /*显示文字*/
  .homedata /deep/ .el-switch__label.is-active {
    display: block;
  }
  .homedata /deep/ .el-switch .el-switch__core,
  .el-switch .el-switch__label {
    width: 80px !important;
  }
  .homedata /deep/ .el-button--mini {
    padding:5px 6px;
  }
</style>